var windowName = "taskInfo";
var Page
apiready = function(){
    onWindowHide(function () {
    })
    onWindowShow(function () {
        checkVote();
    })
    Page = createVM("#Page",{
        id:0,
        en: {
            "id": 36,
            "user": {
                "id": 1,
                "name": "用户_152654612371",
                "phone": "15265461237",
                "avatar": "/ApiCloud/assets/img/userHead.jpeg"
            },
            "cat1": {
                "id": 1,
                "name": "行业一",
                "pic": "/ApiCloud/assets/icons/1.png"
            },
            "cat2": {
                "id": 10,
                "name": "分二",
                "pic": "/ApiCloud/assets/icons/2.png"
            },
            "favor": [],
            "favorProvince": "山东省",
            "favorCity": "东营市",
            "favorArea": "",
            "title": "和弟弟",
            "tips": "意图土豪",
            "address": {
                "id": 4,
                "province": "山东省",
                "city": "东营市",
                "area": "东营区",
                "address": "东营市赛拉维广场-7栋",
                "lat": 37.412543,
                "lon": 118.661927,
                "code": 370502
            },
            "contact": {
                "id": 3,
                "name": "洪三哥",
                "phone": "15265461237"
            },
            "sn": "202001162240042528",
            "bookAt": "2020-01-16T14:30:19+08:00",
            "expireAt": "2020-02-15T22:40:04+08:00",
            "hireAt": null,
            "confirmAt": null,
            "finishAt": null,
            "createAt": "2020-01-16T22:40:04+08:00",
            "status": 0,
            "price": 0,
            "pics": ["http://sano100-tjb.oss-cn-beijing.aliyuncs.com/qz/2HS3QQdts5xpk3P3kCMFnHAGGPtnnkpMDJs2wmbf6Ynb26TamxCE3aNy3deDnpX3.jpg"],
            "type": null
        }
        ,myVote:0
        ,myVoteStatus:0
        , loading: true
        ,gotPhone:0
        ,jifen:""
    },{
        //页面方法
        "init":function () {
            var data = getData4Page()
            var id = data.id
            this.id = id;
            getData()
            var conf = getLocData("conf");
            logJson(conf,"conf_")
            var jifen = conf.JIFEN_GET_PHONE;
            Page.jifen = jifen;


            var getPhone = getLocData("getPhone_" + Page.id)
            if (isTrue(getPhone)) {
                this.gotPhone = getPhone;
            }


        }
        ,getPhone:function () {
            showConfirm("是否使用 "+Page.jifen+" 积分兑换电话？",function () {
                // showLoading();
                apiGet("/app/shop/task/get/phone",{id:Page.id},function (res,code) {
                    // clearLoading();
                    logJson(res)
                    showToast(res.message)
                    if (code == 200) {
                        setTimeout(function () {
                            Page.call(res.data)
                        },1000)
                        setLocData("getPhone_" + Page.id,1)
                        Page.gotPhone = 1;
                    }
                })
            },function () {

            })

            // showToast('coming sonn');
        }
        ,navTo:function (lat,lon,name) {
            showToast("跳转百度地图")
            setTimeout(function () {
                open_bmap(name, lon, lat)
            },500)
        }
    })

    Page.init()
}

function getData() {
    apiGet("/app/task/" + Page.id, {}, function (res, code) {
        logJson(res);
        clearLoading();
        if (code == 200) {
            Page.en = res.data
        } else {
            showToast(code)
        }

    })
}
function checkVote() {
    apiGet("/app/task/" + Page.id + "/check/vote", {}, function (res, code) {
        logJson(res,"checkVote_:_");
        if (code == 200) {
            Page.myVote = res.data.price
            Page.myVoteStatus = res.data.status
        } else {
            showToast(code)
        }

    })
}